

import { getCurrentWebview } from '@tauri-apps/api/webview'
import { register } from '@tauri-apps/plugin-global-shortcut';
const toggle = async () => {
  const appWindow = getCurrentWebview().window;

  const isVisible = await appWindow.isVisible()

  if (isVisible) {
    appWindow.hide()
  } else {
    await appWindow.show()
    await appWindow.setFocus();
  }
}

(async () => {
  await register('Alt+U', (e) => {
    console.log('Shortcut triggered', e);
    if (e.state === 'Released')
      toggle()
  });
})()